local hl_ex__bazhen = fk.CreateSkill {
  name = "hl_ex__bazhen",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["hl_ex__bazhen"] = "八阵",
  [":hl_ex__bazhen"] = "锁定技，若你没有装备防具，视为你装备着【八卦阵】。当你【八卦阵】的黑色判定牌生效后，你摸一张牌。",

  ["$hl_ex__bazhen1"] = "因势而动，变生于阵之间。",
  ["$hl_ex__bazhen2"] = "兵之用者，其状不定见也。",
}

local hl_ex__bazhen_on_use = function (self, event, target, player, data)
  local room = player.room
  room:broadcastPlaySound("./packages/standard_cards/audio/card/eight_diagram")
  room:setEmotion(player, "./packages/standard_cards/image/anim/eight_diagram")
  local skill = Fk.skills["#eight_diagram_skill"]
  skill:use(event, target, player, data)
end
hl_ex__bazhen:addEffect(fk.AskForCardUse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hl_ex__bazhen.name) and not player:isFakeSkill(self) and
      Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none") and
      not player:prohibitUse(Fk:cloneCard("jink")) and
      not player:getEquipment(Card.SubtypeArmor)
      and Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hl_ex__bazhen.name,
    })
  end,
  on_use = hl_ex__bazhen_on_use,
})
hl_ex__bazhen:addEffect(fk.AskForCardResponse, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hl_ex__bazhen.name) and not player:isFakeSkill(self) and
      Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none") and
      not player:prohibitResponse(Fk:cloneCard("jink")) and
      not player:getEquipment(Card.SubtypeArmor)
      and Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = hl_ex__bazhen.name,
    })
  end,
  on_use = hl_ex__bazhen_on_use,
})

hl_ex__bazhen:addEffect(fk.FinishJudge, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.reason == "#eight_diagram_skill" and player:hasSkill(hl_ex__bazhen.name) and
    data.card.color == Card.Black and player:isAlive()
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, hl_ex__bazhen.name)
  end,
})

hl_ex__bazhen:addTest(function(room, me)
  local comp2 = room.players[2]

  FkTest.setNextReplies(me, { "1" })
  FkTest.runInRoom(function()
    room:handleAddLoseSkills(me, "hl_ex__bazhen")
    room:moveCardTo(room:printCard("slash", Card.Heart), Card.DrawPile)
    room:useCard {
      from = comp2,
      tos = { me },
      card = Fk:cloneCard("slash"),
    }
  end)
  lu.assertEquals(me.hp, 4)
  FkTest.setNextReplies(me, { "1", "1", "" })
  FkTest.runInRoom(function()
    room:moveCardTo(room:printCard("slash", Card.Diamond), Card.DrawPile)
    room:useCard {
      from = comp2,
      tos = { me },
      card = Fk:cloneCard("archery_attack"),
    }
    room:moveCardTo(room:printCard("slash", Card.Spade), Card.DrawPile)
    room:useCard {
      from = comp2,
      tos = { me },
      card = Fk:cloneCard("slash"),
    }
  end)
  lu.assertEquals(me.hp, 3)
end)

return hl_ex__bazhen